using System.Linq;
using FluentNHibernate.AutoMap;
using Tools.Domain.Specifications.Constraints;
using Webshop20.Domain.Customers.Core;
using Webshop20.Domain.Common;
using Webshop20.Infrastructure.Persistence.NH.AutoMappings.Conventions.Common;

namespace Webshop20.Infrastructure.Persistence.NH.AutoMappings
{
    public class ForCustomers
    {
        public static AutoPersistenceModel GetPersistenceModel()
        {
           
            return
                AutoPersistenceModel.MapEntitiesFromAssemblyOf<Customer>()
                    .Where(x => x.Namespace == "Webshop20.Domain.Customers.Core" && 
                            !x.Name.EndsWith("DTO") &&
                            !x.Name.EndsWith("Data") &&
                            !x.Name.EndsWith("ConstraintSet") &&
                            x.Name != "NewCustomerRegistration" &&
                            x.Name != typeof(AlwaysExceptForRegistration).Name &&
                            !x.GetInterfaces().Where(interf=>interf.GetType() == typeof(IConstraintContext)).Any() &&
                            x.Name != "Adress"
                        )
                    .ConventionDiscovery.AddFromAssemblyOf<EnumMappingConvention>()
                    .WithSetup(
                                convention=>
                                    {
                                        convention.IsBaseType = bt => bt == typeof (Entity);
                                        convention.IsComponentType = ct => ct == typeof (Adress);
                                    }
                                    );
           
            
        }
    }
}